traverse: Skip already traversed commits
authorColin Walters <walters@verbum.org>
Fri, 16 Nov 2012 17:10:21 +0000 (12:10 -0500)
committerColin Walters <walters@verbum.org>
Fri, 16 Nov 2012 17:35:52 +0000 (12:35 -0500)
This is just more efficient, since e.g. "ostree prune" may invoke
ostree_traverse_commit() multiple times for the same commit.

src/libostree/ostree-traverse.c

index 3dc323e92e4d5c299618104a65f5b66bef4fcf30..20f75865d9bc57809eb3804825c4c685f6115ace 100644 (file)
@@ -155,6 +155,11 @@ ostree_traverse_commit (OstreeRepo      *repo,
       ot_lvariant GVariant *key = NULL;
       ot_lvariant GVariant *commit = NULL;
 
+      key = ostree_object_name_serialize (commit_checksum, OSTREE_OBJECT_TYPE_COMMIT);
+
+      if (g_hash_table_contains (inout_reachable, key))
+        break;
+
       /* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */
       if (!ostree_repo_load_variant_if_exists (repo, OSTREE_OBJECT_TYPE_COMMIT, commit_checksum, &commit, error))
         goto out;
@@ -165,8 +170,7 @@ ostree_traverse_commit (OstreeRepo      *repo,
       if (!commit)
         break;
   
-      key = ostree_object_name_serialize (commit_checksum, OSTREE_OBJECT_TYPE_COMMIT);
-      g_hash_table_replace (inout_reachable, key, key);
+      g_hash_table_add (inout_reachable, key);
       key = NULL;
 
       g_variant_get_child (commit, 7, "@ay", &meta_csum_bytes);